penny = codesters.Sprite("penguin")
def interval():
rand_color = random.choice(["blue", "yellow", "purple", "green"])
rand_x = random.randint(-240, 240)
rand_y = random.randint(-240, 240)
color_star = codesters.Star(rand_x, rand_y, 10, 20, rand_color)
color_star.set_x_speed(4)
color_star.set_y_speed(8)
stage.event_interval(interval, 2)
def collision(sprite, hit_sprite):
color_collided = hit_sprite.get_color()
if color_collided == "blue":
sprite.say("BLUE!")
stage.remove_sprite(hit_sprite)
if color_collided == "yellow":
sprite.say("YELLOW!")
stage.remove_sprite(hit_sprite)
if color_collided == "purple":
sprite.say("PURPLE!")
stage.remove_sprite(hit_sprite)
if color_collided == "green":
sprite.say("GREEN!")
stage.remove_sprite(hit_sprite)
penny.event_collision(collision)
stage.wait(10)
question1 = MCQ(1,"","","","","","", "row")
question1.set_prompt(" 1) How many possible values does rand_color have?")
question1.set_choice_A('1')
question1.set_choice_B('2')
question1.set_choice_C('4')
question1.set_choice_D('unlimited')
question1.set_correct("C")
question2 = MCQ(2,"","","","","","", "row")
question2.set_prompt("2) Which sprite is assigned to the collision event?")
question2.set_choice_A('penny')
question2.set_choice_B('color_star')
question2.set_choice_C('rand_color')
question2.set_choice_D('color_collided')
question2.set_correct("A")
question3 = MCQ(3,"","","","","","", "row")
question3.set_prompt("3) How do you know which sprite is NOT the hit_sprite in a collision?")
question3.set_choice_A('Its name is in front of the event handler.')
question3.set_choice_B('It is the sprite that moves.')
question3.set_choice_C('It is the sprite that the player controls.')
question3.set_choice_D('It is the first sprite created in the program.')
question3.set_correct("A")
repeat_test = True
stop_test = False
def test_script():
global repeat_test
global stop_test
try:
tval1 = question1.correct
except:
tval1 = "DNE"
try:
tval2 = question2.correct
except:
tval2 = "DNE"
try:
tval3 = question3.correct
except:
tval3 = "DNE"
t1 = TestObjective()
t1.add_success(tval1 == True, " ")
t1.add_failure(tval1 == False, "Q1 wrong")
t1.add_failure(tval1 == "DNE", " ")
t2 = TestObjective()
t2.add_success(tval2 == True, " ")
t2.add_failure(tval2 == False, "Q2 wrong")
t2.add_failure(tval2 == "DNE", " ")
t3 = TestObjective()
t3.add_success(tval3 == True, " ")
t3.add_failure(tval3 == False, "Q3 wrong")
t3.add_failure(tval3 == "DNE", " ")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
#tester.display_first_feedback()
if repeat_test == False:
stop_test = True
test_counter = 0
def repeat_tests():
global stop_test
global test_counter
if stop_test == False:
test_script()
if test_counter >= 100:
stop_test = True
stage.event_interval(repeat_tests, .2)